package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.ExceptionHelper;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.BestNewHotModel;
import com.jsyh.maidu.utils.Utils;
import com.jsyh.maidu.views.BestNewHotView;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by Administrator on 2017/6/9.
 */

public class WiringPresenter extends BasePresenter {

    private BestNewHotView bestNewHotView;

    public WiringPresenter(BestNewHotView bestNewHotView) {
        this.bestNewHotView = bestNewHotView;
    }

    public void loadData(final Context context) {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> params = getDefaultMD5Params("first", "home_goods");
        params.put("key", ConfigValue.DATA_KEY);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "first/home_goods", params,
                new BaseDelegate.ResultCallback<BestNewHotModel>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        mLoadingDialog.dismiss();
                        Utils.showToast(context, ExceptionHelper.getMessage(e, context));
                    }

                    @Override
                    public void onResponse(BestNewHotModel response, Object tag) {
                        mLoadingDialog.dismiss();
                        bestNewHotView.bestNewHotData(response);
                    }

                });
    }

}
